package workspace;

public class test52 {
    static class ListNode{
        ListNode next;
        int val;
        public ListNode(int _val){
            this.val = _val;
        }

    }

    public static void main(String[] args) {
        ListNode node = new ListNode(-1);
        ListNode head = node;

        for (int i = 0; i < 10; i++) {
            node.next = new ListNode(i);
            node = node.next;
        }

        ListNode res = rev(head.next);

        while (res!=null){
            System.out.print(res.val);
            res = res.next;
        }
    }

    public static ListNode rev(ListNode node){
        ListNode pre = null;
        ListNode cur = node;
        while(cur!=null){
            ListNode next = cur.next;
            cur.next = pre;
            pre = cur;
            cur = next;
        }
        return pre;
    }


}
